# -*- coding: utf-8 -*-
"""
@author: wyb
@date: 2023/12/2
@time: 11:00
@desc: 从命令行读取请求的位置。
• 从 OpenWeatherMap.org 下载 JSON 天气数据。
• 将 JSON 数据字符串转换成 Python 的数据结构。
• 打印今天和未来两天的天气
Prints the weather for a location from the command line.
"""

import json, requests, sys

# if len(sys.argv) < 2:
#     print('usage:quickweather.py location')
#     sys.exit()
# location = ' '.join(sys.argv[1:])

weatherKey = '12c1b9b3389819de1477dd8c43ef8836'
# url = 'http://api.openweathermap.org/data/2.5/forecast/daily?q=%s&cnt=3' % (location)
url = f"https://restapi.amap.com/v3/weather/weatherInfo?key={weatherKey}&city=440400"
response = requests.get(url)
response.raise_for_status()
data = json.loads(response.text)
print(data)

w = data['lives']
city = w[0]['city']
province = w[0]['province']
location = province + '省' + city
print('Current weather in %s:' % (location))
print(w[0]['weather'])
print(w[0]['temperature'])
print(w[0]['winddirection'])
